package cn.jd.basic.service.impl;

import cn.jd.basic.mapper.BasicMapper;
import cn.jd.basic.query.BaseQuery;
import cn.jd.basic.service.BasicService;
import cn.jd.basic.util.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

public class BasicServiceImpl<T> implements BasicService<T> {
    @Autowired
    private BasicMapper<T> mapper;
    @Override
    public T findById(Long id) {
        return mapper.findById(id);
    }

    @Override
    public List<T> findAll() {
        return mapper.findAll();
    }

    @Override
    public void remove(Long id) {
        mapper.remove(id);
    }

    @Override
    public void deleteByAll(List<Long> ids) {
        mapper.deleteByAll(ids);
    }

    @Override
    public void save(T t) {
        mapper.save(t);
    }

    @Override
    public void update(T t) {
        mapper.update(t);
    }

    @Override
    public PageList<T> queryByPage(BaseQuery query) {
        Integer count = mapper.count(query);
        List<T> departments = mapper.queryByPage(query);
        PageList<T> list = new PageList<>(count, departments);
        return list ;
    }
}
